package cn.javaxc.boot.mvc;

import cn.javaxc.mvcwork.controller.*;
import cn.javaxc.mvcwork.framework.actions.*;
import cn.javaxc.mvcwork.framework.database.*;
import cn.javaxc.mvcwork.modules.admin.*;
import cn.javaxc.mvcwork.modules.login.*;
import cn.javaxc.mvcwork.modules.site.*;
import cn.javaxc.mvcwork.util.common.CommonUtil;
import cn.javaxc.mvcwork.util.helper.*;
import cn.javaxc.mvcwork.util.common.*;
import cn.javaxc.model.base.*;
import java.sql.*;
import java.util.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.*;
import java.util.Date;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.context.annotation.Scope;
import org.springframework.beans.factory.annotation.Autowired;
import cn.javaxc.mvcwork.util.helper.IBaseDAO;
import cn.javaxc.mvcwork.control.web.Result;
import cn.javaxc.mvcwork.controller.web.PagedListInfo;
import cn.javaxc.model.page.*;

@Controller
@Scope("prototype")
@RequestMapping(value = "/VUELogin")
public class MVCBootLogin extends TModuleAction
{ 
  @Autowired
  protected IBaseDAO dao;
	public SQLList<SQLMap> executeMenu() throws Exception{
		

	String path=MVCConfig.getConfig().get("login.mvcpage");
	  if(path!=null&&path.trim().length()>0){
		PagedListInfo searchListInfo = this.getPagedListInfo(MVCConstant.mvc_page_list);
		
		VUEPage page=(VUEPage)Class.forName(path).newInstance();
		SpringUtils.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(page);
		context.setBean(new VUEFormBean());
		page.setContext(context);

//				page.setConnection( db);
		page.setPagination( searchListInfo);

		Object obj=page.onload();
		if (obj instanceof Map){
			Map m=(Map)obj;
			return (SQLList)m.get("mvc_menu");
		}
		return (SQLList)context.getAttribute("mvc_menu");
	}else{
		SQLParam hqlMap=new SQLParam(getRequest());
		hqlMap.put("menutable",MVCConfig.getConfig().getMenuTable());
		DatabaseUtils.createFunction(hqlMap);
		return dao.getusermenu(hqlMap);
	}
  }
	public SQLList executeContainerMenu() throws Exception{
		

		Map hqlMap =buildContainerMenu(getRequest(),context.getParameter("name"),context.getParameter("pid"));
		if (hqlMap==null){
			return new SQLList();
		}
		return dao.containermenu(hqlMap);
  }
  public Map buildContainerMenu(HttpServletRequest request,String name,String pid){
		Map smap=new SQLParam();
	  smap.put("cname",name);
	  smap.put("pid",pid);
	  //获得typesql
//	  String sql="select cm.*,cmp.* from ts_container_menu cm left join ts_container_properties cmp on (cmp.sid=cm.sid) where cm.name=:cname";
//		if (pid!=null){
//			sql+=" and cm.pid=:pid";
//		}
//	  SQLList elist = createList();
//	  elist.buildList(db,sql,"",smap);
	  SQLList elist = dao.containertype(smap);
	  Map m_cmp;
	  if (elist.size()==0){
		return null;
	  }else{
	    m_cmp=((SQLMap)elist.get(0));
	  }
	  //获得菜单列表查询
//	  sql="select cm.*,page.page_desc from ts_container_menu cm \n"+
//		"left join ts_container_page page on (page.pid=cm.pid and page.name=cm.name)\n"+
//		"where cm.sid<>cm.pid and cm.pid=:sid";
//	  if (DatabaseUtils.getDrive(MVCConfig.getConfig().get("gatekeeper.driver")) == DatabaseUtils.MSSQL){
//		  m_cmp.put("isnull","isnull");
//	  }else if (DatabaseUtils.getDrive(MVCConfig.getConfig().get("gatekeeper.driver")) == DatabaseUtils.MYSQL){
//		  m_cmp.put("isnull","ifnull");
//	  }
	  
	  
//	  String CMFILE_MARK=MVCConfig.getConfig().getClassProperty(this.getClass(),"CMFILE_MARK","");
//	  if (CMFILE_MARK!=null&&!"".equals(CMFILE_MARK)){
//		sql+=" "+CMFILE_MARK;
//	  }
	  Map hqlMap=new SQLParam(request,m_cmp);
	  DatabaseUtils.createFunction(hqlMap);
//	  if(m_cmp.get("typesql")!=null&&!"".equals(m_cmp.get("typesql"))){
//			hqlMap.put("typesql",getSql(dao,String.valueOf(m_cmp.get("typesql"))));
//			sql+=" and "+typesql;			
//			if (!(elist instanceof ISQLQuery)){
//				String[] params = HbntUtil.getNamedParameters(db,typesql,true);
//				for (String param:params ){
//					m_cmp.put(param,RequestHelper.getRequestValue(request,param));
//				}
//		  }	  
//	  }
//      if(m_cmp.get("namesql")!=null&&!"".equals(m_cmp.get("namesql"))){
//		hqlMap.put("namesql",getSql(dao,String.valueOf(m_cmp.get("namesql"))));
//	  }
//	  if(m_cmp.get("iconsql")!=null&&!"".equals(m_cmp.get("iconsql"))){
//		hqlMap.put("iconsql",getSql(dao,String.valueOf(m_cmp.get("iconsql"))));
//	  }
//	  return dao.containermenu(hqlMap);
	  return hqlMap;
  }
};
